<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description('Check stepUp() and stepDown() behavior for type=date.');

var input = document.createElement('input');

function setInputAttributes(min, max, step, value) {
    input.min = min;
    input.max = max;
    input.step = step;
    input.value = value;
}

function stepUp(value, step, max, optionalStepCount) {
    setInputAttributes(null, max, step, value);
    if (typeof optionalStepCount != "undefined")
        input.stepUp(optionalStepCount);
    else
        input.stepUp();
    return input.value;
}

function stepDown(value, step, min, optionalStepCount) {
    setInputAttributes(min, null, step, value);
    if (typeof optionalStepCount != "undefined")
        input.stepDown(optionalStepCount);
    else
        input.stepDown();
    return input.value;
}

input.type = 'date';
debug('Invalid value');
shouldBeEqualToString('stepUp("", null, null)', '1970-01-02');
shouldBeEqualToString('stepDown("", null, null)', '1969-12-31');
debug('Non-number arguments');
shouldBeEqualToString('stepUp("2010-02-10", null, null, "0")', '2010-02-10');
shouldBeEqualToString('stepDown("2010-02-10", null, null, "0")', '2010-02-10');
shouldBeEqualToString('stepUp("2010-02-10", null, null, "foo")', '2010-02-10');
shouldBeEqualToString('stepDown("2010-02-10", null, null, "foo")', '2010-02-10');
shouldBeEqualToString('stepUp("2010-02-10", null, null, null)', '2010-02-10');
shouldBeEqualToString('stepDown("2010-02-10", null, null, null)', '2010-02-10');
debug('Normal cases');
shouldBeEqualToString('stepDown("1970-01-04", "2", null)', '1970-01-03');
shouldBeEqualToString('stepUp("2010-02-10", null, null)', '2010-02-11');
shouldBeEqualToString('stepDown("2010-02-10", null, null)', '2010-02-09');
shouldBeEqualToString('stepUp("2010-02-10", null, null, 10)', '2010-02-20');
shouldBeEqualToString('stepDown("2010-02-10", null, null, 11)', '2010-01-30');
shouldBeEqualToString('stepUp("1970-01-01", "4", null, 2)', '1970-01-09');
shouldBeEqualToString('stepDown("1970-01-01", "4", null, 3)', '1969-12-20');
debug('Step=any');
shouldThrow('stepUp("2010-02-10", "any", null)');
shouldThrow('stepDown("2010-02-10", "any", null)');
debug('Overflow/underflow');
shouldBeEqualToString('stepUp("2010-02-10", "3.40282346e+38", null)', '1970-01-01');
shouldBeEqualToString('stepDown("2010-02-10", "3.40282346e+38", null)', '1970-01-01');
shouldBeEqualToString('stepUp("2010-02-10", "1", "2010-02-10")', '2010-02-10');
shouldBeEqualToString('stepDown("2010-02-10", "1", "2010-02-10")', '2010-02-10');

debug('');
</script>
</body>
</html>
